// 生成器
function* gen() {
  console.log(1);
  yield Promise.resolve(1);
  console.log(2);
  yield Promise.resolve(2);
  console.log(3);
  yield Promise.resolve(3);
}

function co(gen) {
  const next = (val) => {
    const result = gen.next(val);
    if (result.done) return;
    Promise.resolve(result.value).then((res) => {
      next(res);
    });
  };
  next(undefined);
}
co(gen());
